<%@include file="/WEB-INF/pages/commons/commons.jsp" %>

<stripes:layout-render name="${_themePath}/basic-layout-without-navbar.jsp" _title="View Space">

<stripes:layout-component name="_head">

        <c:out value="${_head}" escapeXml="false"/>

        <meta content="_viewSpace_" name="_uniquePageId_" />        


        <!-- Sam Skin CSS for TabView -->
        <link rel="stylesheet" type="text/css" href="<c:url value='/yui/build/tabview/assets/skins/sam/tabview.css'/>">

        <!-- JavaScript Dependencies for Tabview: -->
        <script type="text/javascript" src="<c:url value='/yui/build/yahoo-dom-event/yahoo-dom-event.js'/>"></script>
        <script type="text/javascript" src="<c:url value='/yui/build/element/element-min.js'/>"></script>

        <!-- OPTIONAL: Connection (required for dynamic loading of data) -->
        <script type="text/javascript" src="<c:url value='/yui/build/connection/connection-min.js'/>"></script>

        <!-- Source file for TabView -->
        <script type="text/javascript" src="<c:url value='/yui/build/tabview/tabview-min.js'/>"></script>

        <script type="text/javascript">
                // === spaceHeaderMenu
                YAHOO.util.Event.onContentReady("spaceHeaderMenu", function() {
                    var manageHeaderMenu = new YAHOO.widget.Button("spaceHeaderMenuButton",
                                            { type: "menu", menu: "spaceHeaderMenuButtonSelect" });
                    //	"click" event listener for the second Button's Menu instance
                    var onMenuClick = function (p_sType, p_aArgs) {
                        var oEvent = p_aArgs[0];	//	DOM event
                        var oMenuItem = p_aArgs[1];	//	MenuItem instance that was the
                                                    //	target of the event
                        if (oMenuItem) {
                            if ('0' == oMenuItem.value) {   // Add Page
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.page.AddPageActionBean" event="view">
                                        <stripes:param name="page" value=""/>
                                        <stripes:param name="page.spaceId" value="${actionBean.space.id}"/>
                                </stripes:url>
                                document.location.href = '${url}';
                            }
                            else if ('1' == oMenuItem.value) {
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.space.RemoveSpaceActionBean" event="remove">
                                    <stripes:param name="space" value="${actionBean.space.id}"/>
                                </stripes:url>
                                document.location.href = '${url}';
                            }
                            else if ('2' == oMenuItem.value) { // show as wiki page
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.space.SpaceActionBean" event="view">
                                    <stripes:param name="space" value="${actionBean.space.id}"/>
                                </stripes:url>
                                document.location.href='${url}';
                            }
                            else if ('3' == oMenuItem.value) { // atom 1.0
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.general.SpaceFeedsActionBean" event="view">
                                    <stripes:param name="space" value="${actionBean.space.id}"/>
                                    <stripes:param name="feedType" value="atom_1_0" />
                                </stripes:url>
                                document.location.href='${url}';
                            }
                            else if ('4' == oMenuItem.value) { // rss 2.0
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.general.SpaceFeedsActionBean" event="view">
                                    <stripes:param name="space" value="${actionBean.space.id}"/>
                                    <stripes:param name="feedType" value="rss_2_0" />
                                </stripes:url>
                                document.location.href='${url}';
                            }
                            else {
                                alert('unrecognized menu option');
                            }
                        }
                    };
                    //	Add a "click" event listener for the Button's Menu
                    manageHeaderMenu.getMenu().subscribe("click", onMenuClick);
                });
        </script>

        <script type="text/javascript">
            YAHOO.util.Event.onContentReady("tabPanell", function() {
                var myTabs = new YAHOO.widget.TabView("tabPanell");
                var tab0 = myTabs.getTab(0); // view
                var tab1 = myTabs.getTab(1); // edit

                tab0.on("click", function(e) {
                    tab0.set('content', '&nbsp; Loading ...');
                    <stripes:url var="url" beanclass="foo.bar.wiki.web.action.space.ViewSpaceActionBean" event="view">
                        <stripes:param name="space" value="${actionBean.space.id}"/>
                    </stripes:url>
                    document.location.href='${url}';
                });
                tab1.on("click", function(e) {
                    tab1.set('content', '&nbsp; Loading ...');
                    <stripes:url var="url" beanclass="foo.bar.wiki.web.action.space.EditSpaceActionBean" event="view">
                        <stripes:param name="space" value="${actionBean.space.id}"/>
                    </stripes:url>
                    document.location.href='${url}';
                });
            });
        </script>

    </stripes:layout-component>


    <stripes:layout-component name="_topNav">
        <H1>View Space</H1>
        <UL class="gc-topnav-tabs">
            <LI>
                <span id="spaceHeaderMenu">
                <input type="button" id="spaceHeaderMenuButton" value="Options"/>
                <select id="spaceHeaderMenuButtonSelect">
                    <jsecurity:hasPermission name="space:addPage:${actionBean.space.id}">
                        <option value="0">Add Page</option>
                        <option value="x">&nbsp;</option>
                    </jsecurity:hasPermission>
                    <jsecurity:hasPermission name="space:removeSpace:${actionBean.space.id}">
                        <option value="1">Delete This Space</option>
                        <option value="x">&nbsp;</option>
                    </jsecurity:hasPermission>
                    <jsecurity:hasPermission name="space:showPageAsWiki:${actionBean.space.id}">
                        <option value="2">Show As Wiki Page</option>
                        <option value="x">&nbsp;</option>
                    </jsecurity:hasPermission>
                    <jsecurity:hasPermission name="space:viewSpace:${actionBean.space.id}">
                        <option value="3">ATOM 1.0</option>
                        <option value="x">&nbsp;</option>
                        <option value="4">RSS 2.0</option>
                    </jsecurity:hasPermission>
                </select>
                </span>
            </LI>
        </UL>
    </stripes:layout-component>


    <stripes:layout-component name="_content">

        <h2>Description [<a id="_hideDescription" href="#">Hide</a>/<a id="_showDescription" href="#">Show</a>]</h2>
        <div id="_description">
            <p>
                This is where the space details could be viewed. Following are the space details :-
                <ul>
                    <li>Name - Name of the space (could contains only alphanumeric and '_' character)</li>
                    <li>Description - A description about this space itself</li>
                    <li>Creator - The user that creates this space</li>
                    <li>Creation Date - The date when this space was created</li>
                    <li>Modifier - The user that last modified this space details</li>
                    <li>Modification Date - The date where the last modification was done</li>
                    <li>Default Page - The default page in this space that would be rendered when this space is being accessed,
                        else FooBarWiki would provide a default page if none is being specified. To mark a page as the
                        default page of this space, navigate to the page and from the 'Options' drop down box, choose
                        'Mark As Default Page'. Do note that by marking a page as default, it will override previous
                        choice as there could only be one default page for a particular space.</li>
                    <li>Pages - These are the pages that are available in this space</li>
                </ul>
            </p>
            <p/>
            <p/>
            <p/>
        </div>

        <!-- tab panel -->
        <h2>Details</h2>
        <div id="tabPanell" class="yui-navset">
            <ul class="yui-nav">
                <li class="selected"><a href="#tab1"><em>View</em></a></li>
                <li><a href="#tab2"><em>Edit</em></a></li>
            </ul>
            <div class="yui-content">
                <div>
                 <jsecurity:hasPermission name="space:viewSpace:${actionBean.space.id}">
        <stripes:useActionBean
                var="themes"
                alwaysExecuteEvent="false"
                beanclass="foo.bar.wiki.web.action.general.UtilitiesActionBean"
                event="themes" />


        <stripes:messages/>
        <stripes:errors/>

        <h2>Space Details</h2>
        <table width="100%">
        <tr>
            <td>Name: </td>
            <td>${actionBean.space.name}</td>
        </tr>
        <tr>
            <td>Description: </td>
            <td>${actionBean.space.description}</td>
        </tr>
        <tr>
            <td>Theme: </td>
            <td>${actionBean.space.themeName}</td>
        </tr>
        <tr>
            <td>Creator: </td>
            <td>${actionBean.space.creator.username}</td>
        </tr>
        <tr>
            <td>Creation Date: </td>
            <td><fmt:formatDate value="${actionBean.space.creationDate}" pattern="dd/MM/yyyy hh:mm:ss"/></td>
        </tr>
        <tr>
            <td>Modifier: </td>
            <td>${actionBean.space.modifier.username}</td>
        </tr>
        <tr>
            <td>Modification Date:</td>
            <td><fmt:formatDate value="${actionBean.space.modificationDate}" pattern="dd/MM/yyyy hh:mm:ss" /></td>
        </tr>
        <tr>
            <td>Default page:</td>
            <td>${actionBean.space.defaultPage}</td>
        </tr>
        </table>

        <p/>
        <p/>

        <h2>Pages </h2>
        <p/>
        <stripes:url var="url" beanclass="foo.bar.wiki.web.action.space.ViewSpaceActionBean" event="view">
            <stripes:param name="space" value="${actionBean.space.id}"/>
        </stripes:url>
        <displaytag:table id="element" name="${actionBean.pages}" 
                                  sort="external"
                                  style="width:100%;"
                                  excludedParams="*"
                                  defaultsort="1"
                                  defaultorder="ascending"
                                  requestURI="${url}"
                                  requestURIcontext="true">
                    <displaytag_el:column property="name" sortable="false" sortName="name" title="Name" />
                    <displaytag_el:column property="description" sortable="false" sortName="description" title="Description" />
                    <displaytag_el:column property="creator.username" sortable="false" sortName="creator" title="Creator"/>
                    <displaytag_el:column title="Creation Date">
                        <fmt:formatDate value="${element.creationDate}" pattern="dd/MM/yyyy hh:mm:ss a" />
                    </displaytag_el:column>
                    <displaytag_el:column property="modifier.username" sortable="false" sortName="modifier" title="Modifier"/>
                    <displaytag_el:column title="Modification Date">
                        <fmt:formatDate value="${element.modificationDate}" pattern="dd/MM/yyyy hh:mm:ss a"/>
                    </displaytag_el:column>
                    <displaytag_el:column title="Actions">
                        <stripes:link class="_view" beanclass="foo.bar.wiki.web.action.page.PageActionBean" event="view">
                            <stripes:param name="page" value="${element.id}"/>
                            View
                        </stripes:link>
                    </displaytag_el:column>
                </displaytag:table>


                    <!-- close tab panel -->
                    <p/>
                    <p/>
                    <p/>

                    </div>
                </jsecurity:hasPermission>
                <jsecurity:lacksPermission name="space:viewSpace:${actionBean.space.id}">
                    Lacks "space:viewSpace:${actionBean.space.id}" permission
                </jsecurity:lacksPermission>
            </div>
            <div></div>
        </div>
                

    </stripes:layout-component>

</stripes:layout-render>



